﻿/*
 *  XTL - XNA Tool Library, a collection with usefull XNA classes
 * 
 *  Copyright (C) 2009 Sebastian Schäfer, Daniel Schiffner
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XTL
{
    /// <summary>
    /// Static class Extending various base classes.
    /// </summary>
    public static class Extensions
    {
        #region base: Vector3
        /// <summary>
        /// Extension for a vector returning the max component.
        /// </summary>
        /// <param name="v">The vector</param>
        /// <returns>Returns the maxmial value of the vector</returns>
        public static float MaxComponent(this Vector3 v)
        {
            return Math.Max(v.X, Math.Max(v.Y, v.Z));
        }
        /// <summary>
        /// Extension for a vector returning the absolute max component.
        /// </summary>
        /// <param name="v">The vector</param>
        /// <returns>Returns the absolute maximal value of the vector</returns>
        public static float MaxComponentAbs(this Vector3 v)
        {
            return Math.Max(Math.Abs(v.X), Math.Max(Math.Abs(v.Y), Math.Abs(v.Z)));
        }
        /// <summary>
        /// Extentsion for a vector returning the minimum component.
        /// </summary>
        /// <param name="v">The vector</param>
        /// <returns>Returns the minimal value of the vector</returns>
        public static float MinComponent(this Vector3 v)
        {
            return Math.Min(v.X, Math.Min(v.Y, v.Z));
        }
        /// <summary>
        /// Extension for a vector returning the absolute minimum component.
        /// </summary>
        /// <param name="v">The vector</param>
        /// <returns>Returns the absolute minimal value of the vector</returns>
        public static float MinComponentAbs(this Vector3 v)
        {
            return Math.Min(Math.Abs(v.X), Math.Min(Math.Abs(v.Y), Math.Abs(v.Z)));
        }

        /// <summary>
        /// Extension for a vector implementing a Clone() method.
        /// </summary>
        /// <param name="v">The vector</param>
        /// <returns>Returns a copy of the given vector</returns>
        public static Vector3 Clone(this Vector3 v)
        {
            return new Vector3(v.X, v.Y, v.Z);
        }
        #endregion

        #region base: Vector4
        /// <summary>
        /// Extension for a vector to convert it to a Vector3.
        /// </summary>
        /// <param name="v">The vector</param>
        /// <returns>Returns the corresponding Vector3</returns>
        public static Vector3 ToVec3(this Vector4 v)
        {
            return new Vector3(v.X, v.Y, v.Z);
        }
        #endregion

    }
}
